import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class App {
    public static void main(String[] args) throws Exception {
        ServerSocket ss=new ServerSocket(8888);
        Socket socket=ss.accept();
        InputStream ips=socket.getInputStream();
        File file=new File("2.jpg");
        FileOutputStream fops=new FileOutputStream(file);
        int len;
        byte[] buffer=new byte[20];
        while((len=ips.read(buffer))!=-1){
            fops.write(buffer, 0, len);
        }
        ss.close();
        ips.close();
        fops.close();
    }
}
